using System;
using System.Collections.Generic;

namespace MEA.AE_Data
{
	public class FlashBlock
	{
		public enum EFD_Types
		{
			eFD_PA = 0,
			eFD_AWS = 1,
			eFD_DS_1_AE = 2,
			eFD_DS_0_AE = 3,
			eFD_DS_2_AE = 4,
			eFD_DS_2_AE_P = 5,
			eFD_Last_AE = 5,
			eFD_DS_1_AF = 6,
			eFD_DS_0_AF = 7,
			eFD_DS_2_AF = 8,
			eFD_DS_2_AF_P = 9,
			eFD_NoEFD_Type = 10
		}

		public struct XMLFlashBlock
		{
			public bool blockProgrammable;

			public uint checkSum;

			public uint chksumStartAdr;

			public uint chksumEndAdr;

			public bool blockCheckable;

			public uint eraseStartAdr;

			public uint eraseEndAdr;

			public bool blockEraseable;

			public uint id;

			public string name;

			public int nrOfBlocks;

			public EFD_Types fdType;
		}

		private bool blockCheckable;

		private bool blockEraseable;

		private bool blockProgrammable;

		private uint checkSum;

		private uint chksumEndAdr;

		private uint chksumStartAdr;

		private uint eraseEndAdr;

		private uint eraseStartAdr;

		private uint id;

		private string name;

		public string[] HWTypesStr = new string[10] { "", "", "E4-A", "E4-B", "E4-C", "E4P-C", "E4-A", "E4-B", "E4-C", "E4P-C" };

		public EFD_Types fdType = EFD_Types.eFD_NoEFD_Type;

		private List<FlashBlockData> flashdatablocks;

		public int cntOfBlocks;

		public uint Id
		{
			get
			{
				return id;
			}
		}

		public string Name
		{
			get
			{
				return name;
			}
		}

		public List<FlashBlockData> Flashdatablocks
		{
			get
			{
				return flashdatablocks;
			}
		}

		public bool BlockCheckable
		{
			get
			{
				return blockCheckable;
			}
			set
			{
				blockCheckable = value;
			}
		}

		public bool BlockEraseable
		{
			get
			{
				return blockEraseable;
			}
			set
			{
				blockEraseable = value;
			}
		}

		public bool BlockProgrammable
		{
			get
			{
				return blockProgrammable;
			}
			set
			{
				blockProgrammable = value;
			}
		}

		public uint CheckSum
		{
			get
			{
				return checkSum;
			}
		}

		public uint ChksumEndAdr
		{
			get
			{
				return chksumEndAdr;
			}
		}

		public uint ChksumStartAdr
		{
			get
			{
				return chksumStartAdr;
			}
		}

		public uint EraseEndAdr
		{
			get
			{
				return eraseEndAdr;
			}
		}

		public uint EraseStartAdr
		{
			get
			{
				return eraseStartAdr;
			}
		}

		public EFD_Types mkFDType(string type)
		{
			EFD_Types result = EFD_Types.eFD_NoEFD_Type;
			Enum.GetName(typeof(EFD_Types), EFD_Types.eFD_PA);
			switch (type)
			{
			case "eFD_PA":
				result = EFD_Types.eFD_PA;
				break;
			case "eFD_AWS":
				result = EFD_Types.eFD_AWS;
				break;
			case "eFD_DS_0_AE":
				result = EFD_Types.eFD_DS_0_AE;
				break;
			case "eFD_DS_1_AE":
				result = EFD_Types.eFD_DS_1_AE;
				break;
			case "eFD_DS_2_AE":
				result = EFD_Types.eFD_DS_2_AE;
				break;
			case "eFD_DS_2_AE_P":
				result = EFD_Types.eFD_DS_2_AE_P;
				break;
			case "eFD_DS_0_AF":
				result = EFD_Types.eFD_DS_0_AF;
				break;
			case "eFD_DS_1_AF":
				result = EFD_Types.eFD_DS_1_AF;
				break;
			case "eFD_DS_2_AF":
				result = EFD_Types.eFD_DS_2_AF;
				break;
			case "eFD_DS_2_AF_P":
				result = EFD_Types.eFD_DS_2_AF_P;
				break;
			}
			return result;
		}

		public string mkECUHWTypeStr(EFD_Types t)
		{
			string result = string.Empty;
			switch (t)
			{
			case EFD_Types.eFD_DS_1_AE:
			case EFD_Types.eFD_DS_1_AF:
				result = "E4-A";
				break;
			case EFD_Types.eFD_DS_0_AE:
			case EFD_Types.eFD_DS_0_AF:
				result = "E4-B";
				break;
			case EFD_Types.eFD_DS_2_AE:
			case EFD_Types.eFD_DS_2_AF:
				result = "E4-C";
				break;
			case EFD_Types.eFD_DS_2_AE_P:
			case EFD_Types.eFD_DS_2_AF_P:
				result = "E4P-C";
				break;
			}
			return result;
		}

		public EFD_Types mkStr2ECUHWType(string t, bool newType)
		{
			EFD_Types result = EFD_Types.eFD_NoEFD_Type;
			if (newType)
			{
				switch (t)
				{
				case "E4-A":
					result = EFD_Types.eFD_DS_1_AF;
					break;
				case "E4-B":
					result = EFD_Types.eFD_DS_0_AF;
					break;
				case "E4-C":
					result = EFD_Types.eFD_DS_2_AF;
					break;
				case "E4P-C":
					result = EFD_Types.eFD_DS_2_AF_P;
					break;
				}
			}
			else
			{
				switch (t)
				{
				case "E4-A":
					result = EFD_Types.eFD_DS_1_AE;
					break;
				case "E4-B":
					result = EFD_Types.eFD_DS_0_AE;
					break;
				case "E4-C":
					result = EFD_Types.eFD_DS_2_AE;
					break;
				case "E4P-C":
					result = EFD_Types.eFD_DS_2_AE_P;
					break;
				}
			}
			return result;
		}

		public FlashBlock()
		{
		}

		public FlashBlock(ref XMLFlashBlock fb)
		{
			blockProgrammable = fb.blockProgrammable;
			checkSum = fb.checkSum;
			chksumStartAdr = fb.chksumStartAdr;
			chksumEndAdr = fb.chksumEndAdr;
			blockCheckable = fb.blockCheckable;
			eraseStartAdr = fb.eraseStartAdr;
			eraseEndAdr = fb.eraseEndAdr;
			blockEraseable = fb.blockEraseable;
			id = fb.id;
			flashdatablocks = new List<FlashBlockData>();
			name = fb.name;
			fdType = fb.fdType;
			cntOfBlocks = fb.nrOfBlocks;
		}
	}
}
